<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
    <title>jQuery Mobile Demos</title>
    <script type="text/javascript" src="cordova.js"></script>
    <script type='text/javascript' src="js/vendors/hammer.js"></script>
    <script type="text/javascript">
        function pay() {
            window.alipay.pay({
                "subject": "测试标题",
                "body": "我是测试内容",
                "price": "0.01",
                "tradeNo": new Date().getTime(),
                "notifyUrl": "http://alcoholways.com/api/paynotify"
            }, function(msgCode) {
                console.log(msgCode)
            }, function(msg) {
                console.log(msg)
            })
        }

        var saveImgToLocal = function(url) {
            var canvas, context, imageDataUrl, imageData;
            var img = new Image();
            img.onload = function() {
                canvas = document.createElement('canvas');
                canvas.width = img.width;
                canvas.height = img.height;
                context = canvas.getContext('2d');
                context.drawImage(img, 0, 0);
                window.canvas2ImagePlugin.saveImageDataToLibrary(
                    function(msg) {
                        console.log(msg);
                    },
                    function(err) {
                        console.log(err);
                    },
                    canvas
                );
            };
            img.src = url;
        }

        function wechat() {
            Wechat.isInstalled(function(data) {
                console.log(data);
            }, function(data) {
                console.log('error:%O', data)
            });

            Wechat.share({
                message: {
                    title: "这是我Title",
                    description: "安东尼奥真棒",
                    mediaTagName: "不知道干嘛用的",
                    thumb: "https://mmbiz.qlogo.cn/mmbiz_png/ZPeUKc755PUusgNzibR8SicxmjqlFr8rzddibCxZulUE9EB5AoiaEP8IvoNk46tUKoeA9PqZ0pzJK8ycnB0oNwdN1A/0?wx_fmt=png",
                    media: {
                        type: Wechat.Type.WEBPAGE, // webpage
                        webpageUrl: "http://alcoholways.com/" // webpage
                    }
                },
                scene: Wechat.Scene.TIMELINE // share to Timeline
            }, function() {
                alert("Success");
            }, function(reason) {
                alert("Failed: " + reason);
            })
        }

        function wechatfridend() {
            alert('dddd');
            Wechat.isInstalled(function(data) {
                console.log(data);
            }, function(data) {
                console.log('error:%O', data)
            });
            console.log(Wechat.Scene);
            Wechat.share({
                message: {
                    title: "这是我Title",
                    description: "安东尼奥真棒",
                    thumb: "https://mmbiz.qlogo.cn/mmbiz_png/ZPeUKc755PUusgNzibR8SicxmjqlFr8rzddibCxZulUE9EB5AoiaEP8IvoNk46tUKoeA9PqZ0pzJK8ycnB0oNwdN1A/0?wx_fmt=png",
                    media: {
                        type: Wechat.Type.WEBPAGE, // webpage
                        webpageUrl: "http://wine.moqle.com/wx/?plat=100&code=041rNqL40Nd9ZG18rrN40FAkL40rNqLQ&state=null" // webpage
                    }
                },
                scene: Wechat.Scene.SESSION // share to Timeline
            }, function() {
                alert("Success");
            }, function(reason) {
                alert("Failed: " + reason);
            })
        }

        function testHammer() {
            var myElement = document.getElementById('myElement');
            var press = document.getElementById('press');

            // create a simple instance
            // by default, it only adds horizontal recognizers
            var mc = new Hammer(myElement);

            // listen to events...
            mc.on("press", function(ev) {
                console.log(ev);
                press.textContent = ev.type + " gesture detected.";
            });
        }
    </script>
</head>

<body>
    <div data-role="page">
        <div>
            <button onclick="pay()">pay</button>
            <button onclick="wechat()">wechat</button>
            <button onclick="wechatfridend()">wechatfridend</button>
            <button onclick="testHammer()">initHammer</button>
            <button onclick="saveImgToLocal('http://wine.moqle.com:80/dimg/view/1e1f8886157a24c98d97ffa.jpg')">saveimg</button>
        </div>
        <div id="myElement">
            <img src="http://wine.moqle.com:80/dimg/view/1e1f8886157a24c98d97ffa.jpg" width=400 height=400>
        </div>
        <label id="press" for="">ts</label>
    </div>

</body>

</html>